import { http } from "@/utils/http";
import { MenuModel, MenuRouter } from "@/api/model/menuModel";

enum Api {
  getMenuRouter = "/menu/menuRouter",
  MenuChildren = "/menu/children",
  SaveMenu = "/menu/save",
}

export function saveMenu(menu: MenuModel) {
  return http.post<MenuModel>({
    url: Api.SaveMenu,
    params: menu,
  });
}

export function getMenuChildren(parentId?: string) {
  return http.get<MenuModel[]>({
    url: Api.MenuChildren,
    params: { parentId },
  });
}

export function getMenuRouter() {
  return http.get<MenuRouter[]>({
    url: Api.getMenuRouter,
  });
}

export function changeState(id: string, state: boolean) {
  return http.post<Boolean>({
    url: `/menu/state/${id}/${state}`,
  });
}

export function deleteMenu(id: string) {
  return http.post<string>({
    url: `/menu/deleteMenu/${id}`,
  });
}
